<style>
.source_name{width:20%;}
td.source_name{text-align:left;}
</style>
<div class="row">
<!-- 表示一个成功的或积极的动作 -->
<a href="{:U('Ad/index')}"><button type="button" class="btn btn-primary">广告位</button></a>
<a href="{:U('Ad/adlist')}"><button type="button" class="btn btn-primary active">所有广告</button></a>
<a href="{:U('Ad/mobile_ad')}"><button type="button" class="btn btn-primary">手机广告</button></a>
</div>
<table class="table table-hover table-responsive">
   <thead>
      <tr>
         <th class="source_name">名称</th>
         <th>类型</th>
         <th>状态</th>
         <th>操作</th>
         <th>开始时间</th>
         <th>结束时间</th>
         <th>添加时间</th>
      </tr>
   </thead>
   <tbody>
   <volist name="data" id="data">
      <tr>
         <td class="source_name">{$data.name}</td>
         <td>{$data.type}</td>
         <td>{$data.status_text}</td>
         <td>
			<a href="javascript:void(0);" data-id="{$data.id}" class="del_btn">删除</a>
			<switch name="data.status" >
				<case value="1">
					<a href="javascript:void(0);" data-id="{$data.id}" class="close_btn">关闭</a>
				</case>
				<case value="0">
					<a href="javascript:void(0);" data-id="{$data.id}" class="open_btn">开启</a>
				</case>
			</switch>
			
			<a href="javascript:void(0);" data-id="{$data.id}" class="edit_btn">修改</a>
		</td>
         <td>{$data.start_time|date="Y-m-d H:i",###}</td>
		<td>{$data.end_time|date="Y-m-d H:i",###}</td>
         <td>{$data.time|date="Y-m-d H:i:s",###}</td>
      </tr>
    </volist>
   </tbody>
</table>
{$page}
<!-- 模态框（Modal） -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" 
   aria-labelledby="myModalLabel" aria-hidden="true">
   <div class="modal-dialog">
      <div class="modal-content">
         <div class="modal-body">
         <form role="form" id="collect_form" method="get" action="{:U('Source/batchAlbum')}">
  			<div class="form-group">
    			<label for="code">广告代码</label>
    			<textarea id="code"class="form-control" rows="5"></textarea>
    			<input type="hidden" id="ad_id"/>
  			</div>
		</form>
         </div>
         
         <div class="modal-footer">
            <button type="button" class="btn btn-default" 
               data-dismiss="modal">关闭
            </button>
            <button type="button" id="ensure_edit" class="btn btn-primary">确定修改</button>
         </div>
      </div><!-- /.modal-content -->
</div><!-- /.modal -->
</div>
<script>
$(function(){
	$(".edit_btn").click(function(){
		var id=$(this).attr('data-id');
		$.get("{:U('Ad/get_code')}",{id:id},function(data){
			$("#code").val(data['code']);
		});
		$("#ad_id").val(id);
		$("#myModal").modal('show');
	});
	$(".del_btn").click(function(){
		if(confirm('您确定要删除该广告吗？删除之后将不能再恢复')){
			$.get("{:U('Ad/del_ad')}",{id:$(this).attr('data-id')},function(data){
				if(data==1){
					alert('恭喜您，广告删除成功！');
					location.reload();
				}else{
					alert('很遗憾，广告删除失败，请重试！');
				}
			});
		}
	});
	//关闭广告
	$(".close_btn").click(function(){
		$.get("{:U('Ad/set_status')}",{id:$(this).attr('data-id'),status:0},function(data){
			if(data==1){
				alert('恭喜您，广告关闭成功！');
				location.reload();
			}else{
				alert('很遗憾，广告关闭失败，请重试！');
			}
		});
	});
	
	//开启广告
	$(".open_btn").click(function(){
		$.get("{:U('Ad/set_status')}",{id:$(this).attr('data-id'),status:1},function(data){
			if(data==1){
				alert('恭喜您，广告开启成功！');
				location.reload();
			}else{
				alert('很遗憾，广告开启失败，请重试！');
			}
		});
	});
	
	//确定修改广告
	$("#ensure_edit").click(function(){
		if($("#code").val()==''){
			alert('广告代码不得为空！');
			return false;
		}else{
			$.post("{:U('Ad/edit_ad')}",{id:$("#ad_id").val(),code:$("#code").val()},function(data){
				if(data==1){
					alert('恭喜您，修改成功！');
					location.reload();
				}else{
					alert('很遗憾，修改失败，请重试！');
				}
			});
		}
	});
	
});

</script>







